class TFCNAltProj extends TFProjectile;

var vector SimLoc;

replication
{
     reliable if( Role==ROLE_Authority )
          simloc;
}

simulated function PostBeginPlay()
{
	Super.PostBeginPlay();

    SimLoc=Location;
    //Spawn(class'TaskForces.TFCNProjSmoke',,,simloc);
	//Spawn(class'TaskForces.TFCNProjSmoke',,,simloc);
    Settimer(0.05, true);
}

simulated function Timer()
{
    local xemitter e;
    local float x;

    SimLoc+=vector(rotation)*speed/20;

    if ( EffectIsRelevant(simloc,false) )
	{
        Spawn(class'TaskForces.TFCNProjSmoke',,,simloc);

        x=100-lifespan;

        e=Spawn(class'TaskForces.TFCNProjFX',,,simloc);
        e.mColorRange[0].R=100+x*1.5;
        e.mColorRange[1].R=x*2.5;
        e.mStartParticles=1+x/30;

        e=Spawn(class'TaskForces.TFCNProjGlow',,,simloc);
        e.mColorRange[0].B=255-x;
        e.mColorRange[0].R=fmin(255,x*4);
        e.mColorRange[1].G=(100-x)*2;
        e.mColorRange[1].R=fmin(255,100+x*2);
        e.mStartParticles=4+x/15;
    }

    if(e!=none && frand()<(110-lifespan)/100)
        e.PlayownedSound(sound'TFMedia.CNprojsound',SLOT_None,0.3+frand()/3,false,TransientSoundRadius/3,0.8+frand()/2.5);
}

function Detonate()
{
    local xemitter e;

    if ( Role == ROLE_Authority )
    {
        DmgRadius(vect(150,450,750), 1.25, 0.9, damage+(100-lifespan)*100, DamageRadius+(100-lifespan)*25, MyDamageType, MomentumTransfer, simLoc);
    }

   	Spawn(class'Taskforces.tfcnprojexp',,,simloc);
   	Spawn(class'Taskforces.TFCNProjShock',,,simloc);
   	Spawn(class'Taskforces.TFCNProjWave',,,simloc);

    e=Spawn(class'Taskforces.TFCNProjExpFlash',,,simloc);
    e.mColorRange[0].R=100+(100-lifespan)*1.5;
    e.mColorRange[1].R=50+(100-lifespan)*2;
    e.mStartParticles=2+(100-lifespan)/25;

    SetLocation(SimLoc);
    PlaySound(sound'TFMedia.CNBoom',SLOT_None,8.0,false,TransientSoundRadius);
    PlaySound(sound'TFMedia.CNDistantBoom',SLOT_None,2,false,TransientSoundRadius*5);

    Destroy();
}

final function DmgRadius(vector flash, float dmgPctHard, float dmgPctThru, float DamageAmount, float DamageRadius, class<DamageType> DamageType, float Momentum, vector HitLocation )
{
	local actor Victims;
	local float damageScale, dist;
	local vector dir;

	if( bHurtEntry || Role != ROLE_Authority)
		return;

	bHurtEntry = true;
	foreach CollidingActors( class 'Actor', Victims, DamageRadius, HitLocation )
	{
		// don't let blast damage affect fluid - VisibleCollisingActors doesn't really work for them - jag
		if( victims!=none && (Victims != self) && (Victims.Role == ROLE_Authority) && (!Victims.IsA('FluidSurfaceInfo')) )
		{
			dir = Victims.Location - HitLocation;
			dist = FMax(1,VSize(dir));
			dir = dir/dist;
			damageScale = 1 - FMax(0,(dist - Victims.CollisionRadius)/DamageRadius);

            if(!fasttrace(Victims.Location, hitlocation)) damagescale*=dmgPctThru;

            if(pawn(victims)!=none) damagescale=damagescale;
            else damagescale*=dmgPctHard;

            if(damage>0)
            {
                if(tfStation(victims)!=none) tfStation(victims).SkillOnDmg=SkillOnFire;
                Victims.TakeDamage
			    (
				    damageScale * DamageAmount,
				    Instigator,
				    Victims.Location - 0.5 * (Victims.CollisionHeight + Victims.CollisionRadius) * dir,
				    (damageScale * Momentum * dir),
				    DamageType
			    );

			    if(pawn(victims)!=none && pawn(victims).controller!=none && playercontroller(pawn(victims).controller)!=none && flash!=vect(0,0,0))
                    playercontroller(pawn(victims).controller).clientflash(0.1, flash*damagescale);
		    }
		}
	}
	bHurtEntry = false;
}

defaultproperties
{
     Speed=900.000000
     MaxSpeed=900.000000
     Damage=200.000000
     DamageRadius=800.000000
     MomentumTransfer=50000.000000
     MyDamageType=Class'taskforces.DamTypeCNBoom'
     ImpactSound=Sound'WeaponSounds.ShockRifle.ShockRifleExplosion'
     DrawType=DT_None
     bNetTemporary=False
     LifeSpan=100.000000
     DrawScale=7.500000
     SoundOcclusion=OCCLUSION_None
     TransientSoundRadius=750.000000
     bCollideActors=False
     bCollideWorld=False
     ForceType=FT_Constant
     ForceRadius=100.000000
     ForceScale=15.000000
}
